/*oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO

Authors: Nitay Megides
		 Rachel Banino

Project: Exercise 1

Using: LinkedList.h
	   General.h
	   Hw1Types.h

Description:
A List, based on LinkedList, that contains and manages the different 
product types. Each list node has a pointer to TProduct, which contains the 
inforamtion about the relevant product
oOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoOoO*/

#define _CRT_SECURE_NO_WARNINGS
#include "ProductList.h"
#include <stdlib.h>
#include <string.h>



// The local list pointer
static PList list;


BOOL InitializeProductList()
{
	list = InitializeList();
	return (BOOL)(list != NULL);
}

BOOL AddProduct(const TProductID ID, const char* Name)
{
	PProduct product = (PProduct)malloc(sizeof(TProduct));
    AssertOutOfMemory(product);

	product->ID = ID;
	strcpy(product->Name, Name);	

	return (BOOL)((PProduct)AddValue(list, product) == product);
}

PProduct GetProduct(const TProductID ID)
{
	PListItem item = list->Anchor;
	
	while (item != NULL)
	{
		if (((PProduct)item->Value)->ID == ID)
			return ((PProduct)item->Value);

		item = item->NextItem;
	}

	return NULL;
}

void FreeProductList()
{
	FreeList(list);
}
